gaze.coeft <- function(x, col="Std. Error"){
	stopifnot(is.list(x))
	out <- lapply(x, function(y){
		y[ , col]
	})
	return(out)
}
ag$treat_nj_2 <- 0
ag$treat_nj_2[ag$treat==2] <-1

ag$treat_nj_3 <- 0
ag$treat_nj_3[ag$treat==3] <-1

ag$treat_nj_4 <- 0
ag$treat_nj_4[ag$treat==4] <-1

balance_new_jersey_model_confidential <- lm(treat_nj_2~pop+ median.age. + total.population..male + total.population..foreign.born + population.25.years.and.over..high.school.graduate..includes.equivalency. + actual_all_crimes5yr + officers_assaulted5yr +total.population..not.hispanic.or.latino..white.alone + total.population..not.hispanic.or.latino..american.indian.and.alaska.native.alon_share + total.population..not.hispanic.or.latino..asian.alone_share + total.population..not.hispanic.or.latino..black.or.african.american.alone_share + total.population..not.hispanic.or.latino..native.hawaiian.and.other.pacific.isla_share + total.population..hispanic.or.latino_share + tot_clr_murder5yr +  tot_clr_index_violent5yr + tot_clr_index_property5yr + two_party_trump_pct,data = ag[ag$state == 'NJ',])

balance_new_jersey_model_ranking <- lm(treat_nj_3~pop+ median.age. + total.population..male + total.population..foreign.born + population.25.years.and.over..high.school.graduate..includes.equivalency. + actual_all_crimes5yr + officers_assaulted5yr +total.population..not.hispanic.or.latino..white.alone + total.population..not.hispanic.or.latino..american.indian.and.alaska.native.alon_share + total.population..not.hispanic.or.latino..asian.alone_share + total.population..not.hispanic.or.latino..black.or.african.american.alone_share + total.population..not.hispanic.or.latino..native.hawaiian.and.other.pacific.isla_share + total.population..hispanic.or.latino_share + tot_clr_murder5yr +  tot_clr_index_violent5yr + tot_clr_index_property5yr + two_party_trump_pct,data = ag[ag$state == 'NJ',])

balance_new_jersey_model_ranking_confidential <- lm(treat_nj_4~pop+ median.age. + total.population..male + total.population..foreign.born + population.25.years.and.over..high.school.graduate..includes.equivalency. + actual_all_crimes5yr + officers_assaulted5yr +total.population..not.hispanic.or.latino..white.alone + total.population..not.hispanic.or.latino..american.indian.and.alaska.native.alon_share + total.population..not.hispanic.or.latino..asian.alone_share + total.population..not.hispanic.or.latino..black.or.african.american.alone_share + total.population..not.hispanic.or.latino..native.hawaiian.and.other.pacific.isla_share + total.population..hispanic.or.latino_share + tot_clr_murder5yr +  tot_clr_index_violent5yr + tot_clr_index_property5yr + two_party_trump_pct,data = ag[ag$state == 'NJ',])


balance_new_jersey_model_confidential_robust <- coeftest(balance_new_jersey_model_confidential, vcov.=vcovHC(balance_new_jersey_model_confidential, type="HC1")) 

balance_new_jersey_model_ranking_robust <- coeftest(balance_new_jersey_model_ranking, vcov.=vcovHC(balance_new_jersey_model_ranking, type="HC1"))

balance_new_jersey_model_ranking_confidential_robust <- coeftest(balance_new_jersey_model_ranking_confidential, vcov.=vcovHC(balance_new_jersey_model_ranking_confidential, type="HC1")) 

stargazer(balance_new_jersey_model_confidential, balance_new_jersey_model_ranking, balance_new_jersey_model_ranking_confidential,
		  type = "latex", 
		  digits=2, 
		  star.cutoffs = c(0.05, 0.01, 0.001), 
		  intercept.bottom = FALSE, 
		  se = gaze.coeft(list(balance_new_jersey_model_confidential_robust, balance_new_jersey_model_ranking_robust, balance_new_jersey_model_ranking_confidential_robust)), 
		  keep.stat = c("rsq", "n", "f"), 
		  dep.var.labels = c("Confidentiality Treatment", "Ranking Treatment", "Ranking and Confidentiality Treatment"),
		  covariate.labels = c("Intercept", "Population","Median Age", "Male population", "Foreign born population", "% > 25 with high school or more", "Total crimes", "Officers assaulted", "White population", "Native American/Alaskan Native population", "Asian Population", "African American population", "Hawaiian and Pacific Islander population", "Hispanic Population", "Murder clearance rate", "Violent crime clearance rate", "Property crime clearance rate", "Trump vote share (two party)"),
		  out="results/tabled1.tex"
		  )

